package org.xteam.sled.model;

import java.util.ArrayList;
import java.util.List;

import org.xteam.sled.semantic.exp.Exp;
import org.xteam.sled.semantic.exp.ExpVar;

public class LatentPattern extends BasePattern<LatentDisjunct>{

	public LatentPattern(String name, List<LatentDisjunct> disjuncts) {
		super(name, disjuncts);
	}

	public LatentPattern(String name) {
		super(name);
	}

	public LatentPattern(LatentDisjunct disjunct) {
		super(null, disjunct);
	}
	
	public LatentPattern or(LatentPattern other) {
		return (LatentPattern) super.or(other);
	}
	
	public LatentPattern seq(LatentPattern other) {
		return (LatentPattern) super.seq(other);
	}

	public LabelledPattern injectLatent() {
		List<LabelledDisjunct> elements = new ArrayList<LabelledDisjunct>();
		for (LatentDisjunct disjunct : disjuncts) {
			elements.add(disjunct.injectLatent());
		}
		return new LabelledPattern(name, elements);
	}

	@Override
	protected BasePattern<LatentDisjunct> createPattern(String name) {
		return new LatentPattern(name);
	}

	public static LatentPattern latentLabel(ExpVar exp) {
		return new LatentPattern(new LatentDisjunct(new LatentSequence(new LatentLabel(exp))));
	}

}
